#!/bin/bash

# That's a sample standard post-commit hook that checks if a current branch is already managed by git machete,
# and if it isn't, suggests to add it onto its inferred upstream.

# Don't do anything if we're in a detached HEAD state.
git machete show current >/dev/null 2>/dev/null || exit 0

# If the branch is already managed, do nothing.
git machete is-managed >/dev/null 2>/dev/null && exit 0

# Hooks are run by git with stdin set to /dev/null which would make it impossible for 'git machete add' to collect interactive input,
# hence the redirect from /dev/tty.
git machete add </dev/tty
